const connection = require("../app/database");


class AuthServices {
  async login(user) {
    const { name, password } = user;

    const statement = `SELECT password,name FROM users WHERE name = ? AND password = ? `;

    const result = await connection.execute(statement, [name, password]);
    console.log("查询结果123", result[0])

    // 数据库查数据
    // return "登陆成功"
    return result[0]
  }

  // 查询该用户和评论的用户id 是否一样的  权限
  async isSameUser(id, moment_id) {
    const statement = `
      SELECT
      u.id id,
      u.name name,
      m.id moment_id,
      m.content content
      FROM
      moment m LEFT JOIN users u ON u.id = m.user_id WHERE u.id = ? And m.id = ?
    `;
    const res = await connection.execute(statement, [id, moment_id]);
    // console.log(res[0])
    return res;

  }
};


module.exports = new AuthServices()